﻿<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>销售任务</title>
    <!-- head 中 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css">
    <link href="${ctxStatic}/plugin/jquery-weui/lib/weui.min.css" type="text/css" rel="stylesheet"/>
    <link href="${ctxStatic}/plugin/jquery-weui/css/jquery-weui.css" type="text/css" rel="stylesheet"/>
    <style>
        .top_bar {
            height: 7vh;
            line-height: 7vh;
            position: relative;
            background: #3399fe;
        }
        .top_bar a.back_history {
            position: absolute;
            left: 10px;
            top: 8px;
            height: 30px;
        }
        .top_bar h2 {
            color: #fff;
            font-size: 18px;
            font-weight: 400;
            /*margin-left: 10px;*/
            text-align: center;
        }
        .top_bar a.finish {
            position: absolute;
            right: 10px;
            top: 1px;
            color: #fff;
        }
    </style>
</head>
<body ontouchstart ng-app="config" ng-controller="configCtrl" ng-init="init()" >

<div class="top_bar txt_center f18">
    <h2>项目管理</h2>
    <a href="${ctx}/sale/saleTask/saleTaskRecordList?id={{getId}}" class="finish" ng-show="canClose">查看沟通记录</a>
</div>
<%--<div style="text-align: right;margin-right: 20px;margin-top: 10px;">
    <a href="${ctx}/sale/saleTask/saleTaskRecordList" >查看交流明细 &gt;</a>
</div>--%>
<%--客户名称--%>
<div id="chooseCus" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="confirmCustomer" >确定</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default close-popup" >关闭</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="addPupor('addCus')">新增</a>
        </div>
        <article class="weui-article" style="margin-top: -10px;">
            <%--<h1>大标题</h1>--%>
            <div class="weui-cells__title">请选择人员</div>
            <div class="weui-cells weui-cells_radio">
                <label class="weui-cell weui-check__label" ng-repeat="x in customerlist">
                    <div class="weui-cell__bd" >
                        <input type="radio" class="weui-check" name="customer" value="{{x.id}}" text="{{x.name}}" ng-checked="customerId==x.id">{{x.name}}
                        <span class="weui-icon-checked" style="float: right;" ></span>
                    </div>
                    <%--<div class="weui-cell__ft">
                        <span class="weui-icon-checked"></span>
                    </div>--%>
                </label>
                <%--<a href="javascript:void(0);" class="weui-cell weui-cell_link">
                    <div class="weui-cell__bd">添加更多</div>
                </a>--%>
            </div>
        </article>

    </div>
</div>
<%--添加客户--%>
<div id="addCus" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="saveCustomer" >保存</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="closeAddPupor('Cus')" >取消</a>
        </div>
        <article class="weui-article" style="margin-top: 10px;">
            <%--<h1>大标题</h1>--%>
            <form id="cusForm">
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cells__title">新增客户信息</div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="name">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">上级单位</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="superiorUnit">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">地址</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="address">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">区域</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="region">
                            <input class="weui-input" type="hidden" name="sort" value="1">
                        </div>
                    </div>
                </div>
            </form>
        </article>

    </div>
</div>
<%--联系人名称--%>
<div id="chooseCon" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="confirmContact" >确定</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default close-popup" >关闭</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="addPupor('addCon')">新增</a>
        </div>
        <article class="weui-article" style="margin-top: -10px;">
            <%--<h1>大标题</h1>--%>
            <div class="weui-cells__title">请选择联系人</div>
            <div class="weui-cells weui-cells_radio">
                <label class="weui-cell weui-check__label" ng-repeat="x in contactlist">
                    <div class="weui-cell__bd" >
                        <input type="checkbox" class="weui-check" name="contact" value="{{x.id}}" text="{{x.name}}" ng-checked="x.ischeck">{{x.name}}
                        <span class="weui-icon-checked" style="float: right;" ></span>
                    </div>
                    <%--<div class="weui-cell__ft">
                        <span class="weui-icon-checked"></span>
                    </div>--%>
                </label>
            </div>
        </article>

    </div>
</div>
<%--添加联系人--%>
<div id="addCon" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="saveContact" >保存</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="closeAddPupor('Con')" >取消</a>
        </div>
        <article class="weui-article" style="margin-top: 10px;">
            <%--<h1>大标题</h1>--%>
            <form id="conForm">
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cells__title">新增联系人信息</div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="name">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">部门</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="department">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">电话</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="tel">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">职务</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="job">
                        </div>
                    </div>
                </div>
            </form>
        </article>

    </div>
</div>
<%--合作伙伴--%>
<div id="chooseFri" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="confirmFriend" >确定</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default close-popup" >关闭</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="addPupor('addFri')">新增</a>
        </div>
        <article class="weui-article" style="margin-top: -10px;">
            <%--<h1>大标题</h1>--%>
            <div class="weui-cells__title">请选择合作伙伴</div>
            <div class="weui-cells weui-cells_radio">
                <label class="weui-cell weui-check__label" ng-repeat="x in friendlist">
                    <div class="weui-cell__bd" >
                        <input type="checkbox" class="weui-check" name="friend" value="{{x.id}}" text="{{x.name}}" ng-checked="x.ischeck">{{x.name}}
                        <span class="weui-icon-checked" style="float: right;" ></span>
                    </div>
                </label>
            </div>
        </article>

    </div>
</div>
<%--添加合作伙伴--%>
<div id="addFri" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="saveFriend" >保存</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" onclick="closeAddPupor('Fri')" >取消</a>
        </div>
        <article class="weui-article" style="margin-top: 10px;">
            <%--<h1>大标题</h1>--%>
            <form id="friForm">
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cells__title">新增作伙伴信息</div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="name">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">部门</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="contract">
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label">电话</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="text" name="tel">
                        </div>
                    </div>
                </div>
            </form>
        </article>

    </div>
</div>
<%--相关人员--%>
<div id="choosePer" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary"id="confirmPerson" >确定</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default close-popup" >关闭</a>
        </div>
        <article class="weui-article" style="margin-top: -10px;">
            <%--<h1>大标题</h1>--%>
            <div class="weui-cells__title">请选择人员</div>
            <div class="weui-cells weui-cells_radio">
                <label class="weui-cell weui-check__label" ng-repeat="x in personlist">
                    <div class="weui-cell__bd" >
                        <div>
                            <input type="checkbox" class="weui-check" name="person" value="{{x.loginName}}" text="{{x.name}}" ng-checked="x.ischeck" >{{x.name}}
                            <span class="weui-icon-checked" style="float: right;" ></span>
                        </div>
                        <%-- <div ng-show="ischeck!=true">
                             <input type="checkbox" class="weui-check" name="person" value="{{x.loginName}}" text="{{x.name}}">{{x.name}}
                         </div>--%>

                    </div>
                    <%--<div class="weui-cell__ft">
                        <span class="weui-icon-checked"></span>
                    </div>--%>
                </label>
            </div>
        </article>

    </div>
</div>
<div>
    <%--<header class='demos-header' style="text-align: center;">
        <h1 class="demos-title">项目管理</h1>
    </header>--%>
    <input type="hidden" name="" id="currentUserId" value="${fns:getUser()}">
    <form id="totalForm">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">任务名称</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" placeholder="请输入任务名称" name="taksName" value="{{saleTask.taksName}}" ng-readonly="state">
            </div>
        </div>
        <div class="weui-cell ">
            <div class="weui-cell__bd"><label class="weui-label">客户名称</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft" ng-show="!state">
                <a href="javascript:void(0);" class=" weui-cell_link"  onclick="chooseCustomer()">
                    <div class="weui-cell__bd">+点击添加</div>
                </a>
            </div>
        </div>
        <div class="weui-cells" style="margin-top: 0px;" ng-show="customer!=null">
            <div class="weui-cell">
                <%--<div class="weui-cell__hd" onclick="deleteCustomer()">
                    <img src="" alt="" style="width:20px;margin-right:5px;display:block">
                </div>--%>
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{customer.name}}</p>
                </div>
            </div>
        </div>
        <%-- <div class="weui-cell">
             <div class="weui-cell__hd"><label class="weui-label">联系人</label></div>
             &lt;%&ndash;<div class="weui-cell__bd">
                 <input class="weui-input" type="text" value="" onclick="choosePerson()">
             </div>&ndash;%&gt;
         </div>--%>
        <div class="weui-cell ">
            <div class="weui-cell__bd"><label class="weui-label">联系人</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft" ng-show="!state">
                <a href="javascript:void(0);" class=" weui-cell_link"  onclick="chooseContact()">
                    <div class="weui-cell__bd">+点击添加</div>
                </a>
            </div>
        </div>
        <div class="weui-cells" style="margin-top: 0px;" >
            <div class="weui-cell" ng-repeat="x in chooseContactList">
                <%-- <div class="weui-cell__hd" onclick="deleteContact()">
                     <img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>--%>
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{x.name}}</p>
                </div>
            </div>
        </div>

        <div class="weui-cell ">
            <div class="weui-cell__bd"><label class="weui-label">合作伙伴</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft" ng-show="!state">
                <a href="javascript:void(0);" class=" weui-cell_link"  onclick="chooseFriend()">
                    <div class="weui-cell__bd">+点击添加</div>
                </a>
            </div>
        </div>
        <div class="weui-cells" style="margin-top: 0px;" >
            <div class="weui-cell" ng-repeat="x in chooseFriendList">
                <%--<div class="weui-cell__hd" onclick="deleteFriend()">
                    <img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>--%>
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{x.name}}</p>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">合同额</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text"  value="{{saleTask.contractAmount}}" name="contractAmount" placeholder="请输入合同额" ng-readonly="state">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">完成日期</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input"  type="date" value="{{saleTask.completeTime | date:'yyyy-MM-dd' }}" placeholder="请输入完成日期" name="completeTime" ng-readonly="state"><%--id="time-format"--%>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">发包方式</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" value="{{saleTask.packetMode}}" placeholder="请输入发包方式" name="packetMode" ng-readonly="state">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">所属行业</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" value="{{saleTask.industry}}" placeholder="请输入所属行业" name="industry" ng-readonly="state">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">任务类型</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" value="{{saleTask.taskType}}" placeholder="请输入合同额" name="taskType" ng-readonly="state">
            </div>
        </div>
        <%--<div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label"></label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" value="{{saleTask.competitor}}" placeholder="请输入竞争对手" name="competitor" ng-readonly="state">
            </div>
        </div>--%>
        <div class="weui-cell ">
            <div class="weui-cell__bd"><label class="weui-label">竞争对手</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" placeholder="请输入竞争对手" id="competitor" ng-readonly="state">
            </div>
            <div class="weui-cell__ft" ng-show="!state">
                <a href="javascript:void(0);" class=" weui-cell_link"  ng-click="addCompetitor()">
                    <div class="weui-cell__bd">+点击添加</div>
                </a>
            </div>
        </div>
        <div class="weui-cells" style="margin-top: 0px;" >
            <div class="weui-cell" ng-repeat="x in chooseCompetitor">
                <div class="weui-cell__hd" ng-click="removeCompetitor($index)">
                    <img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{x}}</p>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">项目概述</label></div>
        </div>
        <div class="weui-cells weui-cells_form" style="margin-top: 0px;">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <textarea class="weui-textarea" placeholder="请输入项目概况描述" rows="3" name="taskDescription" id="taskDescription" value="{{saleTask.taskDescription}}" ng-readonly="state">{{saleTask.taskDescription}}</textarea>
                    <%--<div class="weui-textarea-counter"><span>0</span>/200</div>--%>
                </div>
            </div>
        </div>
        <div class="weui-cell ">
            <div class="weui-cell__bd"><label class="weui-label">相关人员</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft" ng-show="!state">
                <a href="javascript:void(0);" class=" weui-cell_link"  onclick="choosePerson()">
                    <div class="weui-cell__bd">+点击添加</div>
                </a>
            </div>
        </div>
        <div class="weui-cells" style="margin-top:0px;" >
            <div class="weui-cell" ng-repeat="x in choosePersonList">
                <%--<div class="weui-cell__hd" onclick="deletePerson()">
                    <img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>--%>
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{x.name}}</p>
                </div>
            </div>
        </div>
    </form>
    <div class="weui-btn-area" style="text-align: center;" ng-show="!state">
        <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" style="width: 100px;height: 40px;font-size: 15px;margin-left: auto; margin-right: auto;" ng-click="saveTotal()" ng-show="canSave">保&nbsp;&nbsp;存</a>
        <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default" style="width: 100px;height: 40px;font-size: 15px;margin-left: auto; margin-right: auto;" ng-show="canClose" ng-click="closeSubmit()" >关&nbsp;&nbsp;闭</a>
    </div>
</div>
<script src="${ctxStatic}/plugin/jquery/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/angular/angular.js"></script>
<script src="${ctxStatic}/plugin/jquery-validation/1.14.0/jquery.validate.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/js/jquery-weui.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/fastclick.js"></script>
<script src="https://cdn.bootcss.com/jquery-json/2.6.0/jquery.json.min.js"></script>
<script>
    var app = angular.module('config', []);
    app.controller('configCtrl',function($scope) {
        $scope.init = function(){

            $scope.getId = GetQueryString("id");
            //$scope.getId = "edc49f59cbb14d1593853bd9a1ba9793";

            $scope.currentUserId = $("#currentUserId").val();

            //关闭按钮开关
            $scope.canClose = false;
            $scope.canSave=true;

            //项目状态
            $scope.state=false;


            //获取客户列表
            $scope.getCustomerList();
            //获取相关人员
            $scope.getPersonList();
            //获取合作伙伴
            $scope.contactlist=[];
            $scope.getFriendList();

            //选中的客户
            $scope.customer;//对象
            //获取选中的联系人信息
            $scope.chooseContactList;//列表
            //获取选中的合作伙伴信息
            $scope.chooseFriendList;//列表
            //获取选中的相关人员信息
            $scope.choosePersonList;//列表
            //竞争对手
            $scope.chooseCompetitor = [];


            if($scope.getId!=""&&$scope.getId!=undefined){
                //关闭按钮开关
                $scope.canClose = true;


                //获取修改信息
                $scope.getEditData($scope.getId);
                //获取修改页面中选中的相关人员的显示
                $scope.getChoosePerson();
                //获取修改页面中选中的联系人的显示
                $scope.getChooseContact();
                //获取修改页面中选中的合作伙伴的显示
                $scope.getChooseParten();


            }






            //获取联系人列表
            //$scope.getContactList();
            /*if($scope.customer === null){
             $scope.isHaveCus = true;
             }else{
             $scope.isHaveCus = false;
             }
             console.log($scope.isHaveCus);*/


        };

        //获取修改页面中选中的相关人员的显示
        $scope.getChoosePerson = function(){
            $scope.choosePersonList = [];
            for(var i=0;i<$scope.personlist.length;i++){
                if($scope.personlist[i].ischeck){
                    var person = {};
                    person.name=$scope.personlist[i].name;
                    person.loginName=$scope.personlist[i].loginName;
                    $scope.choosePersonList.push(person);
                }
            }
        };


        //获取修改页面中选中的联系人的显示
        $scope.getChooseContact = function(){
            $scope.chooseContactList = [];
            for(var i=0;i<$scope.contactlist.length;i++){
                if($scope.contactlist[i].ischeck){
                    var contact = {};
                    contact.name=$scope.contactlist[i].name;
                    contact.id=$scope.contactlist[i].id;
                    $scope.chooseContactList.push(contact);
                }
            }
            //获取旧的选中的联系人
            //$scope.oldChooseContactList = $scope.chooseContactList;
        };


        //获取修改页面中选中的合作伙伴的显示
        $scope.getChooseParten= function(){
            $scope.chooseFriendList = [];
            for(var i=0;i<$scope.friendlist.length;i++){
                if($scope.friendlist[i].ischeck){
                    var parten = {};
                    parten.name=$scope.friendlist[i].name;
                    parten.id=$scope.friendlist[i].id;
                    $scope.chooseFriendList.push(parten);
                }
            }
            //获取旧的选中的合作伙伴
            //$scope.oldChooseFriendList = $scope.chooseFriendList;
        };


        //获取修改信息
        $scope.getEditData = function(id){
            $.ajax({
                url:"${ctx}/sale/saleTask/weChatForm",
                async:false,
                type:"POST",
                data:{"id":id},
                success:function(respon){
                    $scope.saleTask=respon.body.saleTask;
                    if($scope.saleTask.state==2){
                        if($scope.currentUserId==$scope.$scope.saleTask.createBy.id){
                            //项目状态
                            $scope.state=true;
                        }
                        if($scope.currentUserId!=$scope.$scope.saleTask.createBy.id){
                            //项目状态
                            $scope.canSave=false;
                        }



                    }


                    //绑定选中的相关人员
                    var concerned = $scope.saleTask.concerned;
                    if(concerned!=""&&concerned!=null){
                        $scope.concernedArry =[];
                        $scope.concernedArry = concerned.split(",");
                        for(var i=0;i<$scope.concernedArry.length;i++){
                            for(var j=0;j<$scope.personlist.length;j++){
                                if($scope.concernedArry[i]==$scope.personlist[j].loginName){
                                    $scope.personlist[j].ischeck=true;
                                }

                            }
                        }
                    }

                    //获取选中的客户信息
                    $scope.customerInformation = $scope.saleTask.customerInformation;
                    $scope.customerId = "";
                    if($scope.customerInformation!=null){
                        $scope.customerId = $scope.customerInformation.id;
                        $scope.customer = {};
                        $scope.customer.id=$scope.customerId;
                        $scope.customer.name=$scope.customerInformation.name;
                    }
                    //绑定选中的的联系人
                    if($scope.customerId!=""){
                        $scope.getContactList($scope.customerId);
                        //获取旧的选中的联系人
                        $scope.oldChooseContactList = $scope.saleTask.saleContactsList;
                        if($scope.oldChooseContactList==null || $scope.oldChooseContactList==undefined){
                            $scope.oldChooseContactList = [];
                        }
                        for(var i=0;i<$scope.oldChooseContactList.length;i++){
                            var customer = $scope.oldChooseContactList[i].customerContact.id;
                            for(var j=0;j<$scope.contactlist.length;j++){
                                if(customer==$scope.contactlist[j].id){
                                    $scope.contactlist[j].ischeck=true;
                                }
                            }
                        }

                    }else{
                        $scope.oldChooseContactList = [];
                    }


                    //绑定选中的的合作伙伴
                    if($scope.saleTask.salePartnerList!=null){
                        //获取旧的选中的合作伙伴
                        $scope.oldChooseFriendList = $scope.saleTask.salePartnerList;

                        for(var i=0;i<$scope.oldChooseFriendList.length;i++){
                            var partner = $scope.oldChooseFriendList[i].partner.id;
                            for(var j=0;j<$scope.friendlist.length;j++){
                                if(partner==$scope.friendlist[j].id){
                                    $scope.friendlist[j].ischeck=true;
                                }
                            }
                        }

                    }else{
                        $scope.oldChooseFriendList = [];
                    }

                    //获取竞争对手
                    if($scope.saleTask.competitor!=null){
                        $scope.chooseCompetitor = $scope.saleTask.competitor.split("|");
                    }




                }
            });


        };





        //关闭项目
        $scope.closeSubmit = function(){
            $.prompt({
                title: '确认关闭项目？',
                text: '',
                input: '请输入理由',
                empty: false, // 是否允许为空
                onOK: function (input) {
                    $.ajax({
                        url:"${ctx}/sale/saleTask/finish",
                        async:false,
                        type:"POST",
                        data:{"finishReason":input,"id":$scope.getId},
                        success:function(respon){
                            if(respon.success){
                                $scope.init();
                            }else{
                                $.toast(respon.msg, "text");
                            }

                        }
                    });
                },
                onCancel: function () {
                    //点击取消
                }
            });
        };





        //获取客户列表
        $scope.getCustomerList=function(){
            $.ajax({
                url:"${ctx}/customer/customerInformation/listData",
                async:false,
                type:"POST",
                success:function(respon){
                    $scope.customerlist=respon.body.list;
                }
            });
        };

        //获取联系人
        $scope.getContactList=function(id){
            $.ajax({
                url:"${ctx}/customer/customerContact/listData",
                async:false,
                data:{"customerInformation.id":id},
                success:function(respon){
                    $scope.contactlist=[];
                    $scope.contactlist=respon.body.list;
                    console.log($scope.contactlist);
                    $scope.$apply();
                }
            });
        };

        //获取合作伙伴
        $scope.getFriendList=function(){
            $.ajax({
                url:"${ctx}/partner/partner/listData",
                async:false,
                type:"POST",
                success:function(respon){
                    $scope.friendlist=respon.body.list;
                    console.log($scope.friendlist);
                }
            });
        };

        //获取相关人员
        $scope.getPersonList=function(){
            $.ajax({
                url:"${ctx}/sys/user/listData",
                async:false,
                type:"POST",
                success:function(respon){
                    $scope.personlist=[];
                    $scope.personlist= respon.body.list;
                }
            });
        };



        //获取选中的客户信息  确认客户信息
        $("#confirmCustomer").click(function(){
            $scope.customer = {};
            $scope.customer.id=$("input[name='customer']:checked").val();
            $scope.customer.name=$("input[name='customer']:checked").attr("text");
            $scope.$apply();

            //console.log($("input[name='customer']:checked").attr("text"));
            //console.log($scope.customer);
            //关闭遮罩层
            $.closePopup("#chooseCus");
            //根据选中的客户信息  获取联系人信息
            if($scope.customer!="" && $scope.customer!=undefined){
                $scope.getContactList($scope.customer.id);
            }
        });

        //获取选中的联系人信息
        $("#confirmContact").click(function(){
            $scope.chooseContactList=[];
            $("input[name='contact']:checked").each(function(){
                var person = {};
                person.name=$(this).attr("text");
                person.id = $(this).val();
                $scope.chooseContactList.push(person);
            });
            $scope.$apply();
            //关闭遮罩层
            $.closePopup("#chooseCon");
        });

        //获取选中的合作伙伴信息
        $("#confirmFriend").click(function(){
            $scope.chooseFriendList=[];
            $("input[name='friend']:checked").each(function(){
                var person = {};
                person.id = $(this).val();
                person.name = $(this).attr("text");
                $scope.chooseFriendList.push(person);
            });
            $scope.$apply();
            //关闭遮罩层
            $.closePopup("#chooseFri");
        });

        //获取选中的相关人员信息
        $("#confirmPerson").click(function(){
            $scope.choosePersonList=[];
            $("input[name='person']:checked").each(function(){
                var person = {};
                person.name=$(this).attr("text");
                person.loginName=$(this).val();
                $scope.choosePersonList.push(person);
                //personList.push($(this).val());
            });
            $scope.$apply();
            console.log($scope.choosePersonList);
            //关闭遮罩层
            $.closePopup("#choosePer");
        });

        //添加竞争对手
        $scope.addCompetitor = function(){
            var value = $("#competitor").val();
            if(value!="" && value!=undefined){
                $scope.chooseCompetitor.push(value);
            }
            $("#competitor").val("");
        };

        //移除竞争对手
        $scope.removeCompetitor = function(no){
            $scope.chooseCompetitor.splice(no,1);
        };




        //添加客户
        $("#saveCustomer").click(function(){
            var params = {};
            params = queryInfos("cusForm");
            console.log(params);
            $.ajax({
                url:"${ctx}/customer/customerInformation/save",
                async:false,
                type:"POST",
                data:params,
                success:function(respon){
                    if(respon.success){
                        //先关闭添加的遮罩层
                        closeAddPupor("Cus");
                        //刷新客户列表
                        $scope.getCustomerList();
                        $scope.$apply();
                    }else{
                        $.toast("新增失败！", "text");
                    }

                }
            });
        });

        //添加联系人
        $("#saveContact").click(function(){
            var params = {};
            params = queryInfos("conForm");
            var customerId=$("input[name='customer']:checked").val();
            console.log(params);
            $.ajax({
                url:"${ctx}/customer/customerContact/weChatSave",
                async:false,
                type:"POST",
                data:{"customerInformation.id":customerId,"name":params.name,"department":params.department,"tel":params.tel,"job":params.job},
                success:function(respon){
                    if(respon.success){
                        //先关闭添加的遮罩层
                        closeAddPupor("Con");
                        //刷新连联系人列表
                        if(customerId!="" && customerId!=undefined){
                            $scope.getContactList(customerId);
                            $scope.$apply();
                        }
                    }else{
                        $.toast("新增失败！", "text");
                    }

                }
            });
        });

        //添加合作伙伴
        $("#saveFriend").click(function(){
            var params = {};
            params = queryInfos("friForm");
            console.log(params);
            $.ajax({
                url:"${ctx}/partner/partner/weChatSave",
                async:false,
                type:"POST",
                data:params,
                success:function(respon){
                    if(respon.success){
                        //先关闭添加的遮罩层
                        closeAddPupor("Fri");
                        //刷新客户列表
                        $scope.getFriendList();
                        $scope.$apply();
                    }else{
                        $.toast("新增失败！", "text");
                    }

                }
            });
        });

        $scope.saveTotal = function(){
            var params = {};
            params = queryInfos("totalForm");
            //客户id
            var customerInformation = {};
            customerInformation.id =$("input[name='customer']:checked").val();
            params.customerInformation=customerInformation;
            //联系人
            var saleContactsList = [];
            if($scope.chooseContactList!=null){
                for(var i=0;i<$scope.chooseContactList.length;i++){
                    var SaleContacts ={};
                    var customerContact = {};
                    customerContact.id=$scope.chooseContactList[i].id;
                    SaleContacts.delFlag = "0";
                    SaleContacts.customerContact=customerContact;
                    saleContactsList.push(SaleContacts);
                }
            }
            //params.saleContactsList=saleContactsList;
            //合作伙伴
            var salePartnerList = [];
            if($scope.chooseFriendList!=null){
                for(var i=0;i<$scope.chooseFriendList.length;i++){
                    var SalePartner={};
                    var partnerN ={};
                    partnerN.id=$scope.chooseFriendList[i].id;
                    SalePartner.delFlag = "0";
                    SalePartner.partner = partnerN;
                    salePartnerList.push(SalePartner);
                }
            }
            //params.salePartnerList=salePartnerList;
            //相关人员
            var concerned = "";
            if($scope.choosePersonList!=null){
                for(var i=0;i<$scope.choosePersonList.length;i++){
                    concerned += $scope.choosePersonList[i].loginName;
                    if(i!=$scope.choosePersonList.length-1){
                        concerned +=",";
                    }
                }
            }
            params.concerned=concerned;

            var competitor = "";
            if($scope.chooseCompetitor!=null){
                for(var i=0;i<$scope.chooseCompetitor.length;i++){
                    competitor += $scope.chooseCompetitor[i];
                    if(i!=$scope.chooseCompetitor.length-1){
                        competitor +="|";
                    }
                }
            }
            params.competitor=competitor;
            console.log(competitor);



            if($scope.getId!=""&&$scope.getId!=null){
                params.id=$scope.getId;
            }
            //比较联系人
            if($scope.getId!="" && $scope.getId!=null){
                for(var i=0;i<$scope.oldChooseContactList.length;i++){
                    var result = false;
                    for(var j=0;j<saleContactsList.length;j++){
                        if($scope.oldChooseContactList[i].customerContact.id==saleContactsList[j].customerContact.id){
                            saleContactsList[j].id=$scope.oldChooseContactList[i].id;
                            var saleTask={};
                            saleTask.id=$scope.getId;
                            saleContactsList[j].saleTask=saleTask;
                            result = true;
                        }
                    }
                    if(!result){
                        var SaleContacts ={};
                        var customerContact = {};
                        customerContact.id=$scope.oldChooseContactList[i].customerContact.id;
                        SaleContacts.delFlag = "1";
                        SaleContacts.customerContact=customerContact;
                        SaleContacts.id=$scope.oldChooseContactList[i].id;
                        //var saleTask={};
                        //saleTask.id=$scope.getId;
                        //SaleContacts.saleTask=saleTask;
                        saleContactsList.push(SaleContacts);
                    }
                }
            }

            //比较合作伙伴
            if($scope.getId!="" && $scope.getId!=null){
                for(var i=0;i<$scope.oldChooseFriendList.length;i++){
                    var result = false;
                    for(var j=0;j<salePartnerList.length;j++){
                        if($scope.oldChooseFriendList[i].partner.id==salePartnerList[j].partner.id){
                            salePartnerList[j].id=$scope.oldChooseFriendList[i].id;
                            var saleTask={};
                            saleTask.id=$scope.getId;
                            salePartnerList[j].saleTask=saleTask;
                            result = true;
                        }
                    }
                    if(!result){
                        var SalePartner={};
                        var partnerN ={};
                        partnerN.id=$scope.oldChooseFriendList[i].partner.id;
                        SalePartner.delFlag = "1";
                        SalePartner.partner = partnerN;
                        SalePartner.id = $scope.oldChooseFriendList[i].id;
                        //var saleTask={};
                        //saleTask.id=$scope.getId;
                        //SalePartner.saleTask=saleTask;
                        salePartnerList.push(SalePartner);
                    }
                }
            }

            //新的联系人
            params.saleContactsList=saleContactsList;
            //新的合作伙伴
            params.salePartnerList=salePartnerList;

            console.log(params);
            $.showLoading("正在加载...");


            $.ajax({
                url:"${ctx}/sale/saleTask/weChatSave",
                async:false,
                type:"POST",
                traditional:true,
                dataType:"JSON",
                contentType:"application/json",
                data:$.toJSON(params),
                success:function(respon){
                    /*if(respon.success){
                        //先关闭添加的遮罩层
                        closeAddPupor("Fri");
                        //刷新客户列表
                        $scope.getFriendList();
                        $scope.$apply();
                    }else{
                        $.toast("新增失败！", "text");
                    }*/
                    if(respon.success){
                        window.location.href="${ctx}/sale/saleTask/weChatList";
                        //$.hideLoading();
                    }else{
                        $.toast("操作失败！", "text");
                    }


                }
            });


        };






        //时间控件
        $("#time-format").datetimePicker({
            title: '选择时间',
            yearSplit: '-',
            monthSplit: '-',
            dateSplit: ' ',
            times: function () {
                return [  // 自定义的时间
                    {
                        values: (function () {
                            var hours = [];
                            for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                            return hours;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ''
                    }
                ];
            },
            onChange: function (picker, values, displayValues) {
                console.log(values);
            }
        });










    });


    //删除客户
    function deleteCustomer() {

    }

    //删除联系人
    function deleteContact() {

    }

    //删除合作伙伴
    function deleteFriend() {

    }

    //删除相关人员
    function deletePerson() {

    }


    /***********************************遮罩层控制**************************************************/

    //选择客户
    $(function () {
        FastClick.attach(document.body);
    });
    $(document).on("open", ".weui-popup-modal", function () {
        console.log("open popup");
    }).on("close", ".weui-popup-modal", function () {
        console.log("close popup");
    });

    //选择相关人员
    function choosePerson() {
        $.openPopup("#choosePer");
    }



    //选择合作伙伴
    function chooseFriend() {
        $.openPopup("#chooseFri");
    }



    //选择客户
    function chooseCustomer() {
        $.openPopup("#chooseCus");
    }


    //选择联系人
    function chooseContact() {
        $.openPopup("#chooseCon");
    }

    //打开添加遮罩层
    function addPupor(puporId) {
        if(puporId=="addCon"){
            var customerId=$("input[name='customer']:checked").val();
            if(customerId==""||customerId==undefined){
                $.toast("请先选择客户！","text");
                return false;
            }
        }
        $.openPopup("#"+puporId);
    }


    //关闭添加覆盖层   选择页面仍然显示
    function closeAddPupor(puporId){
        $.closePopup("#"+puporId);
        $.openPopup("#choose"+puporId);

    }




    /***********************************遮罩层控制**************************************************/
    //获取url参数
    var GetQueryString = function (name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        };

    var queryInfos = function (formId) {
        var d = {};
        var t = $('#'+formId).serializeArray();
        $.each(t, function() {
            if(this.value!=""&&this.value!=null&this.value!=undefined){
                if(this.value.indexOf("number:")>=0){
                    d[this.name] = this.value.split("number:")[1];
                }else {
                    d[this.name] = this.value;
                }
            }
        });
        return d;
    }




</script>
</body>
</html>